[

define integer->isEven => self % 2 == 0
define integer->isOdd => self % 2 == 1

/*
1->isEven
2->isEven
1->isOdd
2->isOdd
*/


// converts unix timestamp back to a UTC date
define integer->asDate => {
  local(d) = date('1/1/1970 00:00:00');
  #d->timezone='UTC';
  #d->add(-second=self)
  return #d
}

// 1242159171->asDate


define integer->log(base=e)::decimal => { return self->asDecimal->log / #base->asDecimal->log }

define integer->pow(exponent) => math_pow(self,#exponent)

define integer->asUnsigned::integer => {
self >= 0 ? return self
return 2->pow((self->abs->bits / 8.0)->ceil->asInteger * 8) + self
}
/*
(-230)->toUnsigned; // 26
'<br>';
(-93)->toUnsigned; // 163
'<br>';
(-1)->toUnsigned; // 255
'<br>';
(-128)->toUnsigned; // 128
'<br>';
*/

define integer->asBoolean::boolean => self == 0 ? return false | return true

define integer->bits::integer => {
self == 0 ? return 1
self < 0 ? return self->asUnsigned->log(2)->floor->asInteger + 1;
return self->log(2)->floor->asInteger + 1
}

/*
loop: -from=-20, -to=20;
loop_count ' ';
loop_count->bits;
'<br>';
/loop;
*/

define integer->bytes::integer => (self->bits / 8.0)->ceil->asInteger


define integer->between(a::integer,b::integer)::boolean => (self >= #a && self <= #b) || (self <= #a && self >= #b)
/*
5->between(2,10)
5->between(10,2)
5->between(7,10)
5->between(10,7)
*/

define integer->sqrt::decimal => math_sqrt(self)
// 10->sqrt

]